<?php
require_once("conn.php");
require_once("functions.php");
$uid = $_GET['id'];
if($_POST){
    $pwd = $_POST['pwd'];
    $res = $mysql->execute("update `user` set `password`='{$pwd}' WHERE `id`=$uid");
    if($res){
        echo "<script>alert('设置成功！')</script>";
        echo "<script>location.href='./focus.php?id={$uid}'</script>";
    }
}
?>
<html>
<head>
    <meta charset="UTF-8">
    <title>微有趣提现密码设置</title>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <link rel="stylesheet" type="text/css" href="assets/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="assets/css/setpassword.css"/>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script>
        function changeSize() {
            var propo = $(window).width() / 640;
            $('html').css('font-size', 40 * propo + 'px');
        }
        changeSize();
        $(window).resize(function () {
            changeSize();
        });
    </script>
    <script>
        //验证密码
        function is_password() {
            var password = $("#pwd1").val();
            if (password == "") {
                alert("密码不能为空");
                return;
            } else if(password.length < 6 || password.length > 16){
                alert("密码不能小于6位或者大于16位");
                return;
            }else {
                return true;
            }
        }
        //验证两次密码是否一致
        function re_password(){
            var password1 = $("#pwd1").val();
            var password2 = $("#pwd2").val();
            if(password1 != password2){
                alert("两次密码不一致");
            }else{
                return true;
            }
        }
        $(function(){
            $("#pwd1").blur(function(){
                is_password();
            });
            $("#pwd2").blur(function(){
                re_password();
            });
        })
        //提交表单
        function submit(){
            if(re_password() && is_password()){
                document.login.submit();
            }else{
            }
        }
    </script>
</head>
<body>
<div class="wrap">
    <div class="forms">
        <form method="post" name="login">
            <div class="pcl phone clearfix">
                <input id="pwd1" name="pwd" type="password" value="" placeholder="设置密码(6-20位字母或数字)">
                <span class="icon3"></span>
            </div>
            <div class="pcl pwd clearfix">
                <input id="pwd2" name="pwd1" type="password" placeholder="再次输入密码(6-20位字母或数字)"/>
                <span class="icon3"></span>
            </div>
    </div>
    <a id="regs_submit" class="reg" onclick="submit()">设置密码</a>
    </form>
</div>
</body>
</html>
